home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / binding / StaticPropertyWatcher.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  3.0 KB  |  113 lines

  1. package mx.binding
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.IEventDispatcher;
  5.    import mx.core.EventPriority;
  6.    import mx.core.mx_internal;
  7.    import mx.events.PropertyChangeEvent;
  8.    
  9.    use namespace mx_internal;
  10.    
  11.    public class StaticPropertyWatcher extends Watcher
  12.    {
  13.       mx_internal static const VERSION:String = "3.2.0.3958";
  14.       
  15.       private var propertyGetter:Function;
  16.       
  17.       private var parentObj:Class;
  18.       
  19.       protected var events:Object;
  20.       
  21.       private var _propertyName:String;
  22.       
  23.       public function StaticPropertyWatcher(param1:String, param2:Object, param3:Array, param4:Function = null)
  24.       {
  25.          super(param3);
  26.          _propertyName = param1;
  27.          this.events = param2;
  28.          this.propertyGetter = param4;
  29.       }
  30.       
  31.       private function eventNamesToString() : String
  32.       {
  33.          var _loc2_:String = null;
  34.          var _loc1_:String = " ";
  35.          for(_loc2_ in events)
  36.          {
  37.             _loc1_ += _loc2_ + " ";
  38.          }
  39.          return _loc1_;
  40.       }
  41.       
  42.       override public function updateParent(param1:Object) : void
  43.       {
  44.          var _loc2_:String = null;
  45.          var _loc3_:IEventDispatcher = null;
  46.          parentObj = Class(param1);
  47.          if(parentObj["staticEventDispatcher"] != null)
  48.          {
  49.             for(_loc2_ in events)
  50.             {
  51.                if(_loc2_ != "__NoChangeEvent__")
  52.                {
  53.                   _loc3_ = parentObj["staticEventDispatcher"];
  54.                   _loc3_.addEventListener(_loc2_,eventHandler,false,EventPriority.BINDING,true);
  55.                }
  56.             }
  57.          }
  58.          wrapUpdate(updateProperty);
  59.       }
  60.       
  61.       private function updateProperty() : void
  62.       {
  63.          if(parentObj)
  64.          {
  65.             if(propertyGetter != null)
  66.             {
  67.                value = propertyGetter.apply(parentObj,[_propertyName]);
  68.             }
  69.             else
  70.             {
  71.                value = parentObj[_propertyName];
  72.             }
  73.          }
  74.          else
  75.          {
  76.             value = null;
  77.          }
  78.          updateChildren();
  79.       }
  80.       
  81.       override protected function shallowClone() : Watcher
  82.       {
  83.          return new StaticPropertyWatcher(_propertyName,events,listeners,propertyGetter);
  84.       }
  85.       
  86.       private function traceInfo() : String
  87.       {
  88.          return "StaticPropertyWatcher(" + parentObj + "." + _propertyName + "): events = [" + eventNamesToString() + "]";
  89.       }
  90.       
  91.       public function get propertyName() : String
  92.       {
  93.          return _propertyName;
  94.       }
  95.       
  96.       public function eventHandler(param1:Event) : void
  97.       {
  98.          var _loc2_:Object = null;
  99.          if(param1 is PropertyChangeEvent)
  100.          {
  101.             _loc2_ = PropertyChangeEvent(param1).property;
  102.             if(_loc2_ != _propertyName)
  103.             {
  104.                return;
  105.             }
  106.          }
  107.          wrapUpdate(updateProperty);
  108.          notifyListeners(events[param1.type]);
  109.       }
  110.    }
  111. }
  112.  
  113.